﻿using System;
using Arch.Common.Mapping;
using Microsoft.Practices.Unity;

namespace Arch.Common.Proxy
{
    public class ProxyTypeResolver : ITypeResolver
    {
        [Dependency]
        public IProxyTypeBuilder ProxyTypeBuilder { get; set; }

        public Type Resolve(Type parent)
        {
            return ProxyTypeBuilder.GetProxy(parent);
        }

        public Type Resolve<T>() where T : class
        {
            return ProxyTypeBuilder.GetProxy<T>();
        }

        public object CreateInstance(Type parent)
        {
            return Activator.CreateInstance(Resolve(parent));
        }

        public T CreateInstance<T>() where T : class
        {
            return Activator.CreateInstance(Resolve<T>()) as T;
        }
    }
}
